//
//  TTUserModel.m
//  ExhibitionHall
//
//  Created by 王洋 on 2019/6/15.
//  Copyright © 2019 王洋. All rights reserved.
//


#import "TTUDIDManager.h"

#import "TTUserModel.h"

@interface TTUserModel ()

@end

@implementation TTUserModel

+ (TTUserModel *)sharedObject {
    static TTUserModel *shareInstance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        shareInstance = [TTUserModel new];
        shareInstance.users = @[].mutableCopy;
    });
    return shareInstance;
}

- (void)initialization {
        
    //normal
    
    [self.userModelDefault setValue:@"" forKey:@"TT_token"];
    [self.userModelDefault setValue:@"" forKey:@"TT_isNewer"];

    [self.userModelDefault setValue:@"" forKey:@"TT_username"];
    [self.userModelDefault setValue:@"" forKey:@"TT_identifier"];
    [self.userModelDefault setValue:@"" forKey:@"TT_userId"];
    [self.userModelDefault setValue:@"" forKey:@"TT_nickname"];
    [self.userModelDefault setValue:@"" forKey:@"TT_realName"];

    [self.userModelDefault setValue:@"" forKey:@"TT_myCode"];
    
    [self.userModelDefault setValue:@"" forKey:@"TT_wechatNo"];
    [self.userModelDefault setValue:@"" forKey:@"TT_realName"];
    
    //IM
    [self.userModelDefault setValue:@"" forKey:@"TT_identifier"];
    [self.userModelDefault setValue:@"" forKey:@"TT_userSig"];

    
    [self.userModelDefault synchronize];
}

- (void)addUserWithDic:(NSMutableDictionary *)userDic {


    [self.userModelDefault synchronize];

    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BA_LoginSuccess" object:nil userInfo:nil];
    
    
    //弹出信息采集页面，内部有完整判断
    

}

//把登录过的多个用户从userInfoArray里面取出来
- (void)configAllUsers {
    for (NSDictionary *dic in self.userInfoArray) {
        UserInfoModel *model = [UserInfoModel modelWithDictionary:dic];
        [self.users addObject:model];
    }
}

- (void)logOut {
    
    [self initialization];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"BA_LogOutSuccess" object:nil userInfo:nil];

}

- (NSMutableArray *)userInfoArray {
    NSMutableArray *userInfoArray = [self.userModelDefault valueForKey:@"TT_userInfoArray"];
    return userInfoArray;
}

-(NSUserDefaults *)userModelDefault {
    if (!_userModelDefault) {
        _userModelDefault = [NSUserDefaults standardUserDefaults];
    }
    return _userModelDefault;
}





@end
